<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="李愧愧">
    <title></title>
    <style>
        body{
            overflow: hidden;
        }
        button{
            width: 100px;
            height: 30px;
            margin-bottom: 20px;
        }
        div{
            width: 100px;
            height: 100px;
            background-color: cornflowerblue;
            position: absolute;
            left: 0px;
            top: 100px;
            animation: move 2s linear infinite alternate;
            /* animation-play-state:running; */
        }
        @keyframes move {
            0%{
                left: 0px;
            }
            100%{
                left: calc(100% - 100px - 100px);
            }
        }
    </style>
</head>
<body>
    <!-- 设置一个按钮：开始和暂停动画，同时修改按钮的名字        v -->
    <!-- 让div移动到距离页面右边100px -->
    <button onclick="play(this)">暂停</button>
    <div></div>
<script>
    var button =document.querySelector('button');
    var div =document.querySelector('div');

    button.onclick=function(ev){
        if(this.innerHTML=='暂停'){
            div.style.animationPlayState = 'paused';
            this.innerHTML='开始';
        }else{
            div.style.animationPlayState = 'running';
            this.innerHTML='暂停';
        }
    }
</script>
</body>
</html>